<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php
    
    class Leave_model extends CI_Model{
        public function __construct(){
            parent::__construct();
            $this->tbl = 'leaveperiods';
            $this->tblstaff = 'staffs';
        }
        
        public function getlist($limit=null){
            if(empty($limit)){
                $limit = 10;
            }
            $data = $this->db->select();
            $this->db->join($this->tblstaff, "$this->tblstaff.idstaff = $this->tbl.idstaff");
            $this->db->limit($limit);
            $data = $data->get($this->tbl);
            $data = $data->result_array();
            return $data;
        }
        
        public function getitem($condition){
            $data = $this->db->select();
            $this->db->where($condition);
            $data = $data->get($this->tbl);
            $data = $data->row_array(); 
            return $data;
        } 
        
        public function additem($data){
            $this->db->insert($this->tbl,$data);
            $affect = $this->db->affected_rows();
            if($affect){
                return true;
            }else{
                return false;
            }   
        } 
        
        public function updateitem($data,$condition){
            $this->db->where($condition);
            $this->db->update($this->tbl,$data);
            $affect = $this->db->affected_rows();
            if($affect){
                return true;
            }else{
                return false;
            }   
        } 
        
        public function deleteitem($condition){
            $this->db->where($condition);
            $this->db->delete($this->tbl);
            $affect = $this->db->affected_rows();
            if($affect){
                return true;
            }else{
                return false;
            }   
        } 
        
        public function getliststaff(){
            $data = $this->db->select(array('idstaff','codestaff','firstname','lastname'));
            $this->db->where(array('active'=>1));
            $data = $data->get($this->tblstaff);
            $data = $data->result_array();
            return $data;
        }
    }

?>



